import uuid
from datetime import datetime

from django.db import models

# Create your models here.

class Platform(models.Model):
    name = models.CharField(max_length=100)
    class Meta:
        db_table = 'tb_platform'

def avatar_upload_path(instance, filename):
    print(instance)
    ext = filename.split('.')[-1]
    filename = f'{uuid.uuid4()}.{ext}'
    now = datetime.now()
    return f'avatars/{now.year}/{now.month}/{now.day}/{filename}'

class Member(models.Model):
    POSITIONChoices = (
        (0, '产品经理'),
        (1, '产品服务员'),
    )
    TYPEChoices = (
        (0, '全职'),
        (1, '团队'),
        (2, '实习生'),
    )
    avatar = models.ImageField(upload_to=avatar_upload_path, null=True, blank=True)
    card = models.CharField(max_length=100)
    platform = models.ForeignKey(Platform, on_delete=models.CASCADE)
    phone = models.CharField(max_length=11)
    position = models.IntegerField(choices=POSITIONChoices, default=1)
    type = models.IntegerField(choices=TYPEChoices, default=2)
    pid_type = models.CharField(max_length=100)
    identity = models.CharField(max_length=100)
    time = models.DateField(auto_now_add=True)

    class Meta:
        db_table = 'tb_member'
